﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Pharmacy.BusinessEntities;

namespace Pharmacy.Repository.Mapping
{
    public class CompraMap : EntityTypeConfiguration<Compra>
    {
        public CompraMap()
        {
            this.HasKey(p => p.Id);

            this.Property(p => p.Id)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            this.Property(p => p.Fecha)
                .IsRequired();

            this.Property(p => p.Total)
                .HasPrecision(9, 2);

            this.ToTable("COMPRA");

            this.Property(p => p.Id).HasColumnName("Id");
            this.Property(p => p.Fecha).HasColumnName("Fecha");
            this.Property(p => p.Total).HasColumnName("Total");

            this.HasRequired(p=>p.Proveedor)
                .WithMany(cc=>cc.Compras)
                .HasForeignKey(c=>c.IdProveedor)
                .WillCascadeOnDelete(false);
        }
    }
}
